package thread;

public class Demo12 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            for(int i = 0; i < 5; i++){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("thread over");
        });

        t.start();

        for (int i = 0; i < 5; i++){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        t.join();//没有wait之类的单词（也有一个wait操作，效果和join是不一样的）
        //main线程中调用t.join就是让main等待t先结束，main后结束
        //main阻塞（该线程暂时不参与cpu调度执行）main线程不能被join

        System.out.println("main over");
    }
}
